﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DTO;
using DAO;

namespace QLDaiLy
{
    public partial class CapNhatGia :XtraUserControl
    {
        public CapNhatGia()
        {
            InitializeComponent();
            LoadDanhSachMatHang();
            LoadDanhSachDonViTinh();
        }

        private void btnThemNhanVien_Click(object sender, EventArgs e)
        {
            if (lookupMatHang.EditValue != "" && lookupDonViTinh.EditValue != "")
            {
                GiaMatHangDTO gia = new GiaMatHangDTO();
                gia.MaMatHang = Convert.ToInt32(lookupMatHang.EditValue.ToString());
                gia.MaDonViTinh = int.Parse(lookupDonViTinh.EditValue.ToString());
                gia.GiaTien = int.Parse(txtDonGia.Text);
                bool kq = GiaMatHangDAO.UpdateGia(gia);
                if (kq)
                {
                    MessageBox.Show("Thêm thành công !");
                }
                else
                {
                    MessageBox.Show("Thêm thất bại !");
                }
            }
            else
            {

                MessageBox.Show("Mặt hàng hay đơn vị không được trống");
            }
        }
        private void LoadDanhSachMatHang()
        {
            List<MatHangDTO> list = new List<MatHangDTO>();
            list = MatHangDAO.LoadDanhSachMatHang();
            lookupMatHang.Properties.DataSource = list;
            lookupMatHang.Properties.ValueMember = "MaMatHang";
            lookupMatHang.Properties.DisplayMember = "TenMatHang";
            DevExpress.XtraEditors.Controls.LookUpColumnInfo col;
            col = new DevExpress.XtraEditors.Controls.LookUpColumnInfo("TenMatHang");
            col.SortOrder = DevExpress.Data.ColumnSortOrder.Ascending;
            lookupMatHang.Properties.Columns.Add(col);
        }
        private void LoadDanhSachDonViTinh()
        {
            List<DonViTinhDTO> list = new List<DonViTinhDTO>();
            list = DonViTinhDAO.LoadDanhSachDonVi();
            lookupDonViTinh.Properties.DataSource = list;
            lookupDonViTinh.Properties.ValueMember = "MaDonVi";
            lookupDonViTinh.Properties.DisplayMember = "TenDonVi";
            DevExpress.XtraEditors.Controls.LookUpColumnInfo colTenLoaiDaiLy;
            colTenLoaiDaiLy = new DevExpress.XtraEditors.Controls.LookUpColumnInfo("TenDonVi");
            colTenLoaiDaiLy.SortOrder = DevExpress.Data.ColumnSortOrder.Ascending;
            lookupDonViTinh.Properties.Columns.Add(colTenLoaiDaiLy);
        }
    }
}
